<html><body>
<?php

class stg_Server
{
	private $_games = array(); // of Game
	private $_users = array(); // of User

	function create_game($name, $universe_name)
	{
		ein("Creating game $name");
		$this->games[$name] = new stg_Game($name, $universe_name, $this);
		eout();
		return $this->games[$name];
	}

	function delete_game($name)
	{
		e("Deleting game $name");
	}

	function create_user($name)
	{
		ein("Creating user $name");
		$this->users[$name] = new stg_User($name, $this);
		eout();
	}

	function delete_user($name)
	{
		e("Deleting user $name");
	}

	public function& __get($name)
	{
		if (method_exists($this, "get_$name"))
		{
			$result = call_user_func(array(&$this, "get_$name"));
			return $result;
		}
		elseif (property_exists($this, "_$name"))
		{
			return $this->{'_'.$name};
		}
		else
		{
			throw new Exception("Property $name does not exist in class ".get_class($this)."!!");
		}
	}

	public function __set($name, $val)
	{
		if (array_key_exists("_$name",get_object_vars($this)))
		{
			$caller_class = get_caller_class();
			$caller_object = get_caller_object();
			if (property_exists($this, '__permissions'))
			{
				$perms = $this->__permissions;
			}
			else
			{
				$perms = array();
			}
			if  (
			    get_class($this) == $caller_class ||
				is_subclass_of($this, $caller_class) ||
			    is_writable_by($caller_object, $perms, $name)
				)
			{
				if (method_exists($this, "set_$name"))
				{
					call_user_func(array(&$this, "set_$name"), $val);
				}
				else
				{
					$this->{"_$name"} = $val;
				}
			}
			else
			{
				throw new Exception("Property $name in class ".get_class($this)." is not writable by ".get_caller_class()." instances");
			}
		}
		else
		{
			throw new Exception("Property $name does not exist in class ".get_class($this)."!!");
		}
	}

}

?>
</body></html>
